summaryrefslogtreecommitdiff
path: root/app/[lng]/evcp/(evcp)/(procurement)/itb-create/page.tsx
blob: 77dc54ee57e3be74f533e8774c2fdebe08e93d1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// app/[lng]/purchase-requests/page.tsx

import * as React from "react";
import { type SearchParams } from "@/types/table";
import { getValidFilters } from "@/lib/data-table";
import { Shell } from "@/components/shell";
import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Plus, FileText, Clock, CheckCircle, XCircle, Send } from "lucide-react";
import Link from "next/link";
import { searchParamsPurchaseRequestCache } from "@/lib/itb/validations";
import { getAllPurchaseRequests, getPurchaseRequestStats } from "@/lib/itb/service";
import { PurchaseRequestsTable } from "@/lib/itb/table/purchase-requests-table";
import { useTranslation } from "@/i18n"

interface PurchaseRequestsPageProps {
  params: Promise<{ lng: string }>;
  searchParams: Promise<SearchParams>;
}

export default async function PurchaseRequestsPage(props: PurchaseRequestsPageProps) {
  const { lng } = await props.params
  const { t } = await useTranslation(lng, 'menu')
  
  const searchParams = await props.searchParams;
  
  // Parse search params
  const search = searchParamsPurchaseRequestCache.parse(searchParams);
  const validFilters = getValidFilters(search.filters);
  
  // Load data
  const promises = Promise.all([
    getAllPurchaseRequests({
      ...search,
      filters: validFilters,
    }),
    getPurchaseRequestStats(),
  ]);

  return (
    <Shell className="gap-4">
      <div className="flex items-center justify-between">
        <div>
          <h2 className="text-2xl font-bold tracking-tight">
            {t('menu.engineering_management.itb')}
          </h2>
          <p className="text-muted-foreground">
            {t('menu.engineering_management.itb_desc')}
          </p>
        </div>
      </div>

      {/* 통계 카드 */}
      <React.Suspense
        fallback={
          <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-6">
            {[...Array(6)].map((_, i) => (
              <Card key={i}>
                <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
                  <CardTitle className="text-sm font-medium">
                    <div className="h-4 w-20 bg-muted animate-pulse rounded" />
                  </CardTitle>
                </CardHeader>
                <CardContent>
                  <div className="h-8 w-12 bg-muted animate-pulse rounded" />
                </CardContent>
              </Card>
            ))}
          </div>
        }
      >
        <PurchaseRequestStats promises={promises} />
      </React.Suspense>
      
      <React.Suspense
        fallback={
          <DataTableSkeleton
            columnCount={13}
            searchableColumnCount={1}
            filterableColumnCount={3}
            cellWidths={[
              "8rem",   // requestCode
              "15rem",  // requestTitle
              "12rem",  // projectCode
              "15rem",  // projectName
              "10rem",  // packageNo
              "8rem",   // status
              "10rem",  // engPicName
              "10rem",  // purchasePicName
              "10rem",  // estimatedBudget
              "10rem",  // requestedDeliveryDate
              "8rem",   // itemCount
              "10rem",  // createdAt
              "8rem",   // actions
            ]}
            shrinkZero
          />
        }
      >
        <PurchaseRequestsTable promises={promises} />
      </React.Suspense>
    </Shell>
  );
}

// 통계 컴포넌트
async function PurchaseRequestStats({ 
  promises 
}: { 
  promises: Promise<[any, any]> 
}) {
  const [, stats] = await promises;

  const statCards = [
    {
      title: "전체",
      value: stats?.total || 0,
      icon: FileText,
      color: "text-blue-500",
    },
    {
      title: "작성중",
      value: stats?.draft || 0,
      icon: Clock,
      color: "text-gray-500",
    },
 
    {
      title: "RFQ 생성",
      value: stats?.rfqCreated || 0,
      icon: Send,
      color: "text-red-500",
    },
  ];

  return (
    <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
      {statCards.map((card, index) => {
        const Icon = card.icon;
        return (
          <Card key={index}>
            <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
              <CardTitle className="text-sm font-medium">
                {card.title}
              </CardTitle>
              <Icon className={`h-4 w-4 ${card.color}`} />
            </CardHeader>
            <CardContent>
              <div className="text-2xl font-bold">{card.value}</div>
            </CardContent>
          </Card>
        );
      })}
    </div>
  );
}

// Metadata
export const metadata = {
  title: "Purchase Request Management",
  description: "Create and manage material purchase requests for projects",
};